﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

namespace H2.NET.Web.Pages
{
    public partial class PHNVD : TaskPage
    {
        #region 属性 Public
        public string color
        {
            get
            {
                return VD_Category.SelectedValue == "1" && TaskAPI.IsBeginStep ? "Blue" : "Black";
            }
        }

        public string color2
        {
            get
            {
                return VD_Category.SelectedValue == "1" || !TaskAPI.IsBeginStep ? "Black" : "Blue";
            }
        }

        public string color3
        {
            get
            {
                return TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit ? "Blue" : "Black";
            }
        }

        public string Vendor_Type
        {
            get
            {
                return ViewState["Vendor_Type"] == null ? "" : (string)ViewState["Vendor_Type"];
            }
            set { ViewState["Vendor_Type"] = value; }
        }

        public string Action_Type
        {
            get
            {
                return ViewState["Action_Type"] == null ? "" : (string)ViewState["Action_Type"];
            }
            set { ViewState["Action_Type"] = value; }
        }

        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //WorkLoad_L.Text = VD_Category.SelectedItem.Text.Substring(3);
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                InitDropDownList();

                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    VD.Checked = true;
                    //Vendor_Type = "NA";
                    Action_Type = "1";
                }
                #endregion

                #region 审批环节
                else
                {
                    #region 加载数据并显示
                    nhvd_Vendor vendor = (nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == TaskAPI.Incident).ListFirst<nhvd_Vendor>();
                    if (vendor != null)
                    {
                        ApplicationNo.Text                  = vendor.ApplicationNo;
                        VD.Checked                          = vendor.VD_Checked == "1";
                        DrpPriority.SelectedValue = vendor.DrpPriority;
                        DMO_DrpPriority.SelectedValue = vendor.DMO_DrpPriority;

                        //WorkLoad_L.Text = vendor.WorkLoad_L;
                        //WorkLoad.Text = vendor.WorkLoad;
                        
                        VD_Vendor_Type.SelectedValue        = vendor.VD_Vendor_Type;
                        Vendor_Type                         = vendor.VD_Vendor_Type;
                        VD_Description_1.Text               = vendor.VD_Description_1;
                        VD_Description_2.Text               = vendor.VD_Description_2;
                        VD_Search_Term.Text                 = vendor.VD_Search_Term;
                        VD_District.Text = vendor.VD_District;
                        VD_Street.Text                      = vendor.VD_Street;
                        VD_Country.Text                     = vendor.VD_Country;
                        VD_Region.SelectedValue             = vendor.VD_Region;
                        VD_City.Text                        = vendor.VD_City;
                        VD_Postal_Code.Text = vendor.VD_Postal_Code;
                       
                        VD_Language.SelectedValue         = vendor.VD_Language;
                        VD_Contact_Person.Text              = vendor.VD_Contact_Person;
                        VD_Telephone.Text                   = vendor.VD_Telephone;
                        VD_Ext_1.Text                       = vendor.VD_Ext_1;
                        VD_Fax_Number.Text                  = vendor.VD_Fax_Number;
                        VD_Bank_Key.Text = vendor.VD_Bank_Key;
                        VD_Ext_2.Text                       = vendor.VD_Ext_2;
                        VD_Email.Text                       = vendor.VD_Email;
                        VD_Bank_Country.Text                = vendor.VD_Bank_Country;
                        VD_Bank_Name.Text                   = vendor.VD_Bank_Name;
                        VD_Bank_Account.Text                = vendor.VD_Bank_Account;
                        VD_Recon_Account.SelectedValue      = vendor.VD_Recon_Account;
                        VD_Cash_Mgmnt_Group.Text  = vendor.VD_Cash_Mgmnt_Group;
                        VD_Payt_Terms.SelectedValue         = vendor.VD_Payt_Terms;
                        VD_Schema_Group.SelectedValue =  vendor.VD_Schema_Group;
                       
                       
                        VD_Payment_Methods.SelectedValue = vendor.VD_Payment_Methods;
                        
                        VD_Order_Currency.Text              = vendor.VD_Order_Currency;
                        VD_Payment_Terms.SelectedValue      = vendor.VD_Payment_Terms;
                        VD_Purchasing_Group.SelectedValue   = vendor.VD_Purchasing_Group;
                        VD_Account_Holder_Name.Text = vendor.VD_Account_Holder_Name;
                        SA_Account_Holder_Name.Text = vendor.SA_Account_Holder_Name;
                        
                        
                       
                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            VD_Company.Text                 = vendor.VD_Company;
                            VD_Pricing_Date_Control.Text    = vendor.VD_Pricing_Date_Control;
                            VD_Acct_statement.Text          = vendor.VD_Acct_statement;
                            VD_Sotr_Key.Text                = vendor.VD_Sotr_Key;
                            VD_Chk_Double_Inv.Checked = vendor.VD_Chk_Double_Inv == "1";
                            VD_Dunn_Procedure.Text = vendor.VD_Dunn_Procedure;
                            VD_GR_Based.Checked = vendor.VD_GR_Based == "1";

                            SA_Company.Text = vendor.SA_Company;
                            SA_Region.Text = vendor.SA_Region;
                            SA_Recon_Account.Text = vendor.SA_Recon_Account;
                            SA_Cash_Mgmnt_Group.Text = vendor.SA_Cash_Mgmnt_Group;
                            SA_Sort_Key.Text = vendor.SA_Sort_Key;
                            SA_Chk_Double_Inv.Checked = vendor.SA_Chk_Double_Inv == "1";
                            SA_Dunn_Procedure.Text = vendor.SA_Dunn_Procedure;
                            SA_Acct_statement.Text = vendor.SA_Acct_statement;
                        }

                        VD_Category.SelectedValue           = vendor.VD_Category;
                        Action_Type                         = vendor.VD_Category;;
                        VD_Area1.Checked                    = vendor.VD_Area == "1";
                        VD_Area2.Checked                    = vendor.VD_Area == "2";
                        VD_Area3.Checked                    = vendor.VD_Area == "3";
                        //if (vendor.VD_Area == "3" & VD_Category .SelectedValue =="1")
                        //{
                        //    SetForeColor(Color.Blue, VD_Telephone_L, VD_Fax_Number_L);
                        //}
                        VD_Vendor_Master_Code.Text          = vendor.VD_Vendor_Master_Code;
                        VD_Customer_sold_to_code.Text       = vendor.VD_Customer_sold_to_code;
                        SA.Checked                          = vendor.SA_Checked == "1";
                        //SA_Temp_Staff.Checked               = vendor.SA_Temp_Staff == "1";
                        SA_Vendor_Master_Code.Text          = vendor.SA_Vendor_Master_Code;
                        SA_Name.Text                        = vendor.SA_Name;
                        SA_Employee_Code.Text = vendor.SA_Employee_Code;
                        
                        
                       
                        
                       
                        SA_City.Text                        = vendor.SA_City;
                        //SA_District.Text                    = vendor.SA_District;
                        SA_Street.Text                      = vendor.SA_Street;
                        SA_Postal_Code.Text                 = vendor.SA_Postal_Code;
                        SA_Telephone.Text                   = vendor.SA_Telephone;
                        SA_Ext_3.Text                       = vendor.SA_Ext_3;
                        SA_Ext_4.Text                       = vendor.SA_Ext_4;
                        SA_Cell_Phone.Text                  = vendor.SA_Cell_Phone;
                        SA_Fax_Number.Text                  = vendor.SA_Fax_Number;
                        SA_Email.Text                       = vendor.SA_Email;
                        SA_Bank_Name.Text                   = vendor.SA_Bank_Name;
                        SA_Bank_Key.Text = vendor.SA_Bank_Key;
                        SA_Bank_Country.Text                = vendor.SA_Bank_Country;
                        SA_Bank_Account.Text                = vendor.SA_Bank_Account;
                        SA_Sales_Person.SelectedValue       = vendor.SA_Sales_Person;
                        SA_Employment_Date.Text             = vendor.SA_Employment_Date;
                        //SA_Personnel_Area.Text              = vendor.SA_Personnel_Area;
                        //SA_EE_Group.SelectedValue           = vendor.SA_EE_Group;
                        //SA_Subarea.SelectedValue            = vendor.SA_Subarea;
                        //SA_EE_Su_Group.Text                 = vendor.SA_EE_Su_Group;
                       

                       

                       
                        SA_Payt_Terms.SelectedValue = vendor.SA_Payt_Terms;
                        SA_Payment_Methods.SelectedValue = vendor.SA_Payment_Methods;
                        

                        SA2.Checked = vendor.SA2_Checked == "1";
                        SA2_Personnel_NO.Text = vendor.SA2_Personnel_NO;
                        SA2_From_Date.Text = vendor.SA2_From_Date;
                        
                        
                        
                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            SA2_EE_Sub_Group.Text = vendor.SA2_EE_Sub_Group;
                            SA2_Language.Text = vendor.SA2_Language;
                            SA2_Personnel_Area.Text = vendor.SA2_Personnel_Area;
                            SA2_EE_Group.Text = vendor.SA2_EE_Group;
                            SA2_Subarea.Text = vendor.SA2_Subarea;
                            SA2_Payr_Area.Text = vendor.SA2_Payr_Area;
                            SA2_City.Text = vendor.SA2_City;
                        }

                        SA2_Action_Type.SelectedValue = vendor.SA2_Action_Type;
                        
                        SA2_Title.SelectedValue = vendor.SA2_Title;
                        SA2_Nickname.Text = vendor.SA2_Nickname;
                        
                        SA2_Last_Name.Text = vendor.SA2_Last_Name;
                        SA2_First_Name.Text = vendor.SA2_First_Name;
                        SA2_Gender.SelectedValue = vendor.SA2_Gender;
                        SA2_Birth_Date.Text = vendor.SA2_Birth_Date;
                        SA2_Street_And_HseNo.Text = vendor.SA2_Street_And_HseNo;
                        
                        SA2_Mobile_Phone_Number.Text = vendor.SA2_Mobile_Phone_Number;
                        SA2_EMail_Address.Text = vendor.SA2_EMail_Address;
                        SAP_Code.Text = vendor.SAP_Code;

                        DMO_SalesSAP_Code.Text = vendor.DMO_SalesSAP_Code;
                        DMO_Employee_Name.Text = vendor.DMO_Employee_Name;
                        if (VD.Checked)
                        {
                            if (VD_Description_2.Text == "")
                            {
                                DMO_Employee_Name.Text = VD_Description_1.Text;
                            }
                            else if (VD_Description_1.Text == "")
                            {
                                DMO_Employee_Name.Text = VD_Description_2.Text;
                            }
                            else if (VD_Description_1.Text != "" & VD_Description_2.Text != "")
                            {
                                DMO_Employee_Name.Text = VD_Description_2.Text;
                            }
                        }
                      
                    }
                    #endregion

                    #region 审批项初始化
                    switch(TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                        //case "Finance":
                        //case "LAM":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                        //case "Manager Approve":
                        //    Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                        //    Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                        //    break;
                    }
                    #endregion
                }
                #endregion

                #region 设置控件禁启用
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, VD, SA, SA2,DrpPriority, SA2_Nickname, VD_Postal_Code, SA_Payt_Terms, VD_Language, SA2_Title, VD_Language, SA2_Action_Type, SA_Payment_Methods, VD_Description_1, VD_Description_2, VD_District, VD_Street, VD_Country, VD_Region, VD_City, VD_Contact_Person, VD_Telephone, VD_Ext_1, SA_Bank_Key, VD_Bank_Key, VD_Fax_Number, VD_Ext_2, VD_Schema_Group, VD_Email, VD_Bank_Country, VD_Bank_Name, VD_Bank_Account, VD_Recon_Account, VD_Payt_Terms, VD_Payment_Methods, VD_Payment_Terms, VD_Order_Currency, VD_Purchasing_Group, VD_Category, VD_Area1, VD_Area2, VD_Area3, VD_Vendor_Master_Code, VD_Customer_sold_to_code, SA_Vendor_Master_Code, SA_Employee_Code, SA_Name, SA_City, SA_Street, SA_Postal_Code, SA_Telephone, SA_Ext_3, SA_Ext_4, SA_Cell_Phone, SA_Fax_Number, SA_Email, SA_Bank_Name, SA_Bank_Country, SA_Bank_Account, SA_Sales_Person, SA_Employment_Date, SA_Account_Holder_Name, VD_Account_Holder_Name, SA2_Personnel_NO, SA2_From_Date, SA2_Last_Name, SA2_First_Name, SA2_Gender, SA2_Birth_Date, SA2_Street_And_HseNo, SA2_Mobile_Phone_Number, SA2_EMail_Address);
                SetEnable(TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve", SAP_Code, DMO_SalesSAP_Code);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                //SetEnable(TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check", WorkLoad);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);
                SetEnable(false, DMO_Employee_Name);

                SetVisible(SA.Checked | SA2.Checked, Sales_SAP_Code_L, DMO_SalesSAP_Code);
                if (TaskAPI.Step == "DMO Maintain" & SA2.Checked)
                {
                    SetForeColor(Color.Blue, SAP_Code_L, Sales_SAP_Code_L);
                }
                if (TaskAPI.Step == "DMO Maintain" & VD.Checked)
                {
                    SetForeColor(Color.Blue, SAP_Code_L, Sales_SAP_Code_L);
                }
                SetVisible(VD_Category.SelectedValue != "1", P1, P2,P3);
                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                }
            }
            #endregion

        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "DMO Maintain") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                //新增workload验证代码
                //if (Assessment1.Assessment.Opinion == "1")
                //{
                //    List<string> vald_s = new List<string>();
                //    vald_s.AddRange(DataValidations());

                //    if (vald_s.Count > 0)
                //    {
                //        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                //        return;
                //    }
                //}
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }
                    
                    TaskAPI.Summary = (VD_Category.SelectedItem.Text.Split(',').Length >= 2 ? VD_Category.SelectedItem.Text.Split(',')[1].Trim() : VD_Category.Text)
                                    + " / " + ApplicationNo.Text + (VD.Checked ? " / Vendor " : "") + (SA.Checked ? " / Employee " : "") + (SA2.Checked ? " / Sales Person " : "");


                    //TaskAPI["Vendor_Type"] = VD.Checked && VD_Vendor_Type.SelectedValue == "内部(Internal)" ? "Internal" : "";
                    TaskAPI["Actions"]        = VD_Category.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == VD_Category.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    //m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.dr2EmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    //if(oc != null)
                    //{
                    //    TaskAPI["R_Manager_Approve2"] = oc.WinID;
                    //}

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
                {
                    TaskAPI["Vendor_Type"]    = VD.Checked && VD_Vendor_Type.SelectedValue == "内部(Internal)" ? "Internal" : "";
                }

                if (TaskAPI.IsBeginStep && !TaskAPI.IsInitiate
                && (Action_Type != VD_Category.SelectedValue || Vendor_Type != VD_Vendor_Type.SelectedValue))
                {
                    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                    if (PreStep.Trim() != "" && PreStep.Trim() != "Manager Approve")
                    {
                        TaskAPI["PreStep"] = "DMO Approve";
                    }
                }

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        nhvd_Vendor vendor = new nhvd_Vendor();
                        if ((nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == TaskAPI.Incident & nhvd_Vendor.user == UserAPI.UserName).Count<nhvd_Vendor>() > 0)
                        {
                            vendor = (nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == TaskAPI.Incident & nhvd_Vendor.user == UserAPI.UserName).ListFirst<nhvd_Vendor>();
                        }
                        else
                        {
                            vendor.Process       = TaskAPI.Process;
                            vendor.Incident      = TaskAPI.Incident;
                            vendor.UserName      = UserAPI.UserName;
                            vendor.UserFullName  = UserAPI.UserFullName;
                            vendor.ApplicationNo = ApplicationNo.Text;
                            vendor.Time          = System.DateTime.Now;
                            vendor.Status        = 0;
                            vendor.Department    = UserAPI.Department;
                        }

                        vendor.VD_Category       = VD_Category.SelectedValue;
                        vendor.Actions           = VD_Category.SelectedItem.Text;
                        vendor.DrpPriority = DrpPriority.SelectedValue;

                        //vendor.WorkLoad_L = WorkLoad_L.Text;

                        vendor.VD_Checked        = VD.Checked ? "1" : "0";
                        vendor.SA_Checked        = SA.Checked ? "1" : "0";
                        vendor.SA2_Checked       = SA2.Checked ? "1" : "0";
                        vendor.DMO_Employee_Name = DMO_Employee_Name.Text;

                        #region VD
                        if (VD.Checked)
                        {
                            vendor.VD_Company               = VD_Company.Text;
                            vendor.VD_Vendor_Type           = VD_Vendor_Type.SelectedValue;
                            vendor.VD_Description_1         = VD_Description_1.Text;
                            vendor.VD_Description_2         = VD_Description_2.Text;
                            vendor.VD_Search_Term           = VD_Search_Term.Text;
                            vendor.VD_Street                = VD_Street.Text;
                            vendor.VD_District = VD_District.Text;
                            vendor.VD_Country               = VD_Country.Text;
                            vendor.VD_Region                = VD_Region.SelectedValue;
                            vendor.VD_City                  = VD_City.Text;
                            
                       
                            vendor.VD_Language              = VD_Language.SelectedValue;
                            vendor.VD_Contact_Person        = VD_Contact_Person.Text;
                            vendor.VD_Telephone             = VD_Telephone.Text;
                            vendor.VD_Ext_1                 = VD_Ext_1.Text;
                            vendor.VD_Fax_Number            = VD_Fax_Number.Text;
                            vendor.VD_Bank_Key = VD_Bank_Key.Text;
                            vendor.VD_Ext_2                 = VD_Ext_2.Text;
                            vendor.VD_Email                 = VD_Email.Text;
                            vendor.VD_Schema_Group = VD_Schema_Group.SelectedValue;
                            vendor.VD_Bank_Country          = VD_Bank_Country.Text;
                            vendor.VD_Bank_Name             = VD_Bank_Name.Text;
                            vendor.VD_Bank_Account          = VD_Bank_Account.Text;
                            vendor.VD_Recon_Account         = VD_Recon_Account.SelectedValue;
                            vendor.VD_Cash_Mgmnt_Group = VD_Cash_Mgmnt_Group.Text;
                            vendor.VD_Sotr_Key = VD_Sotr_Key.Text;
                            
                            vendor.VD_Chk_Double_Inv = VD_Chk_Double_Inv.Checked ? "1" : "0";
                            
                            vendor.VD_GR_Based = VD_GR_Based.Checked ? "1" : "0";
                            vendor.VD_Payt_Terms            = VD_Payt_Terms.SelectedValue;
                            vendor.VD_Payment_Methods = VD_Payment_Methods.SelectedValue;
                            vendor.VD_Postal_Code = VD_Postal_Code.Text;
                            vendor.VD_Order_Currency        = VD_Order_Currency.Text;
                            vendor.VD_Payment_Terms         = VD_Payment_Terms.SelectedValue;
                            vendor.VD_Purchasing_Group      = VD_Purchasing_Group.SelectedValue;
                            vendor.VD_Pricing_Date_Control  = VD_Pricing_Date_Control.Text;
                            vendor.VD_Acct_statement        = VD_Acct_statement.Text;
                            vendor.VD_Category              = VD_Category.Text;
                            vendor.VD_Area                  = VD_Area1.Checked ? "1" : (VD_Area2.Checked ? "2" : "3");
                            vendor.VD_Vendor_Master_Code    = VD_Vendor_Master_Code.Text;
                            vendor.VD_Customer_sold_to_code = VD_Customer_sold_to_code.Text;
                            vendor.VD_Account_Holder_Name = VD_Account_Holder_Name.Text;
                            
                            vendor.VD_Dunn_Procedure=VD_Dunn_Procedure.Text;
                        }
                        #endregion

                        #region SA
                        if (SA.Checked)
                        {
                            //vendor.SA_Temp_Staff            = SA_Temp_Staff.Checked ? "1" : "0";
                            vendor.SA_Vendor_Master_Code    = SA_Vendor_Master_Code.Text;
                            vendor.SA_Name                  = SA_Name.Text;
                            vendor.SA_Employee_Code = SA_Employee_Code.Text;
                            vendor.SA_Company               = SA_Company.Text;
                            vendor.SA_Chk_Double_Inv = SA_Chk_Double_Inv.Checked ? "1" : "0";
                            vendor.SA_Sort_Key = SA_Sort_Key.Text;
                            vendor.SA_Account_Holder_Name = SA_Account_Holder_Name.Text;
                            vendor.SA_Region                = SA_Region.Text;
                            vendor.SA_City                  = SA_City.Text;
                            //vendor.SA_District              = SA_District.Text;
                            vendor.SA_Street                = SA_Street.Text;
                            vendor.SA_Postal_Code           = SA_Postal_Code.Text;
                            vendor.SA_Telephone             = SA_Telephone.Text;
                            vendor.SA_Ext_3                 = SA_Ext_3.Text;
                            vendor.SA_Ext_4 = SA_Ext_4.Text;
                            vendor.SA_Cell_Phone            = SA_Cell_Phone.Text;
                            vendor.SA_Fax_Number            = SA_Fax_Number.Text;
                            vendor.SA_Email                 = SA_Email.Text;
                            vendor.SA_Bank_Name             = SA_Bank_Name.Text;
                            vendor.SA_Bank_Country          = SA_Bank_Country.Text;
                            vendor.SA_Bank_Account          = SA_Bank_Account.Text;
                            vendor.SA_Bank_Key = SA_Bank_Key.Text;
                            vendor.SA_Sales_Person          = SA_Sales_Person.SelectedValue;
                            vendor.SA_Employment_Date       = SA_Employment_Date.Text;
                            //vendor.SA_Personnel_Area = SA_Personnel_Area.Text;
                            //vendor.SA_EE_Group = SA_EE_Group.SelectedValue;
                            //vendor.SA_EE_Su_Group = SA_EE_Su_Group.Text;
                            //vendor.SA_Subarea = SA_Subarea.SelectedValue;
                            vendor.SA_Acct_statement = SA_Acct_statement.Text;
                            vendor.SA_Recon_Account = SA_Recon_Account.Text;
                            vendor.SA_Cash_Mgmnt_Group = SA_Cash_Mgmnt_Group.Text;
                            vendor.SA_Dunn_Procedure = SA_Dunn_Procedure.Text;
                            vendor.SA_Payt_Terms = SA_Payt_Terms.SelectedValue;
                            vendor.SA_Payment_Methods = SA_Payment_Methods.SelectedValue;
                        }
                        #endregion

                        #region SA2
                        if (SA2.Checked)
                        {
                            vendor.SA2_Personnel_NO = SA2_Personnel_NO.Text;
                            vendor.SA2_From_Date = SA2_From_Date.Text;
                            vendor.SA2_Personnel_Area = SA2_Personnel_Area.Text;
                            vendor.SA2_EE_Group = SA2_EE_Group.Text;
                            vendor.SA2_EE_Sub_Group = SA2_EE_Sub_Group.Text;
                            vendor.SA2_Subarea = SA2_Subarea.Text;
                            vendor.SA2_Last_Name = SA2_Last_Name.Text;
                            vendor.SA2_First_Name = SA2_First_Name.Text;
                            vendor.SA2_Gender = SA2_Gender.SelectedValue;
                            vendor.SA2_Birth_Date = SA2_Birth_Date.Text;
                            vendor.SA2_Language = SA2_Language.Text;
                            vendor.SA2_Street_And_HseNo = SA2_Street_And_HseNo.Text;
                            vendor.SA2_City = SA2_City.Text;
                            vendor.SA2_Mobile_Phone_Number = SA2_Mobile_Phone_Number.Text;
                            vendor.SA2_EMail_Address = SA2_EMail_Address.Text;
                            vendor.SA2_Action_Type = SA2_Action_Type.SelectedValue;
                            vendor.SA2_Payr_Area = SA2_Payr_Area.Text;
                            vendor.SA2_Title = SA2_Title.SelectedValue;
                            vendor.SA2_Nickname = SA2_Nickname.Text;
                            
                        }
                        #endregion

                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, vendor);
                    }
                    #endregion

                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion

                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain"||TaskAPI.Step=="DMO Approve")
                    {
                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == TaskAPI.Incident).Edit<nhvd_Vendor>(p =>
                        {
                            p.SAP_Code = SAP_Code.Text;
                            //SetEnable(true, WorkLoad);
                            //p.WorkLoad = WorkLoad.Text;
                            p.DMO_SalesSAP_Code = DMO_SalesSAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;
                        }    
                        );
                    }
                    #endregion

                    #region
                    //if (TaskAPI.Step == "DMO Check")
                    //{
                    //    (nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == TaskAPI.Incident).Edit<nhvd_Vendor>(p =>
                    //    {
                    //        SetEnable(true, WorkLoad);
                    //        p.WorkLoad = WorkLoad.Text;

                    //    });
                    //}

                    //if (TaskAPI.Step == "DMO Approve")
                    //{
                    //    (nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == TaskAPI.Incident).Edit<nhvd_Vendor>(p =>
                    //    {
                    //        SetEnable(true, WorkLoad);
                    //        p.WorkLoad = WorkLoad.Text;

                    //    });
                    //}

                    #endregion

                    #region DMO Check 步骤
                    if (TaskAPI.Step == "DMO Check" && Assessment1.Assessment.Opinion == "1")
                    {
                        (m_VendorMaster.vendor_Code == SAP_Code.Text).Edit<m_VendorMaster>(p =>
                        {
                            p.Status = 1;
                        }
                        );
                        m_VendorMaster m_vm = new m_VendorMaster();
                        if ((m_VendorMaster.vendor_Code == SAP_Code.Text).Count<m_VendorMaster>() > 0)
                        {
                            m_vm = (m_VendorMaster.vendor_Code == SAP_Code.Text).ListFirst<m_VendorMaster>();
                        }
                        else
                        {
                            m_vm.Status = 1;
                        }

                        m_vm.Vendor_Code = SAP_Code.Text;
                        m_vm.Site = "HK";
                        m_vm.Vendor_Name = DMO_Employee_Name.Text;
                        if (SA.Checked)
                        {
                            m_vm.Vendor_Type = "EMP";
                        }
                        else
                        {
                            m_vm.Vendor_Type = "VND";
                        }
                        if (VD_Category.SelectedValue == "1")
                        {
                            m_vm.Sales_SAP_Code = DMO_SalesSAP_Code.Text;
                            m_vm.CreateDate = System.DateTime.Now;
                        }
                        if (VD_Category.SelectedValue == "3")
                        {
                            m_vm.UpdateDate = System.DateTime.Now;
                            m_vm.Status = 0;
                        }
                        else if (VD_Category.SelectedValue == "2")
                        {
                            m_vm.UpdateDate = System.DateTime.Now;
                        }

                        Storage.Save(Storage.Context1, m_vm);
                    }
                    #endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    (nhvd_Vendor.process == TaskAPI.Process & nhvd_Vendor.incident == 0 & nhvd_Vendor.user == UserAPI.UserName).Edit<nhvd_Vendor>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {
            SetVisible(false,P_VD,P_SA);
            switch(((Anthem.CheckBox)sender).ID)
            {
                case "VD":
                    
                    if (VD.Checked)
                    {
                        SA.Checked = false;
                        SA2.Checked = false;
                    }
                    VD.Checked = !(SA.Checked | SA2.Checked);
                    VD_L.Visible = VD.Checked;
                    break;
                case "SA":
                    if (!SA.Checked & !SA2.Checked) SA.Checked = true;
                    VD.Checked = !(SA.Checked | SA2.Checked);
                    SA_L.Visible = SA.Checked;
                    if (!SA.Checked & SA2.Checked) { SA2_L.CssClass = "tabs1"; Tabs_Click(SA2_L, e); }
                    break;
                case "SA2":

                    if (!SA.Checked & !SA2.Checked) SA2.Checked = true;
                    VD.Checked = !(SA.Checked | SA2.Checked);
                    //if (SA2.Checked & VD_Category.SelectedValue != "2") { SA_Email_L.ForeColor = Color.Blue; SA_Cell_Phone_L.ForeColor = Color.Blue; }
                    //else { SA_Email_L.ForeColor = Color.Black; SA_Cell_Phone_L.ForeColor = Color.Black; }
                    SA2_L.Visible = SA2.Checked;


                    break;
            }
            if (SA2.Checked) { SA_Sales_Person.SelectedValue = "Y"; }
            else SA_Sales_Person.SelectedValue = "N";
            InitTabs();

        }
        #endregion

        #region 事件 Category变换
        protected void VD_Category_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetEnable((VD_Category.SelectedValue == "1" || VD_Category.SelectedValue == "2" || VD_Category.SelectedValue == "3" || VD_Category.SelectedValue == "4"),DrpPriority, SA_Payt_Terms, SA_Payment_Methods, VD_Postal_Code,  VD_Description_1, VD_Description_2, VD_Search_Term, VD_District, VD_Street, VD_Country, VD_Region, VD_City, VD_Language, VD_Contact_Person, VD_Telephone, VD_Ext_1, SA_Bank_Key, VD_Bank_Key, VD_Fax_Number, VD_Ext_2, VD_Schema_Group,VD_Email, VD_Bank_Country, VD_Bank_Name, VD_Bank_Account, VD_Recon_Account, VD_Cash_Mgmnt_Group, VD_Payt_Terms, VD_Payment_Methods, VD_Order_Currency, VD_Payment_Terms, VD_Purchasing_Group, VD_Area1, VD_Area2, VD_Area3, VD_Customer_sold_to_code, SA_Name, SA_Employee_Code, SA_City, SA_Street, SA_Postal_Code, SA_Telephone, SA_Ext_3, SA_Ext_4, SA_Cell_Phone, SA_Fax_Number, SA_Email, SA_Bank_Name, SA_Bank_Country, SA_Bank_Account, SA_Sales_Person, SA_Employment_Date, SA_Account_Holder_Name, VD_Account_Holder_Name, SA2_From_Date, SA2_Last_Name, SA2_First_Name, SA2_Gender, SA2_Birth_Date, SA2_Street_And_HseNo, SA2_Mobile_Phone_Number, SA2_EMail_Address, SA2_Nickname, SA2_Title, SA2_Action_Type);
            SetVisible(VD_Category.SelectedValue != "1", P1, P2,P3);
            if(VD_Area3 .Checked) VD_Area_CheckedChanged(VD_Area3, e);
            //WorkLoad_L.Text = VD_Category.SelectedItem.Text.Substring(3);
        }
        #endregion

        #region 事件 Sales_Person
        protected void SA_Sales_Person_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA2.Checked = SA_Sales_Person.SelectedValue == "Y";
            VD_CheckedChanged(SA2, e);
            InitTabs();
        }
        #endregion
      
        #region 事件 Area
        protected void VD_Area_CheckedChanged(object sender, EventArgs e)
        {
            VD_Area1.Checked = false;
            VD_Area2.Checked = false;
            VD_Area3.Checked = false;
            SetForeColor(Color.Black, VD_Telephone_L, VD_Fax_Number_L);

            switch ((sender as Anthem.CheckBox).ID)
            {
                case "VD_Area1":
                    VD_Area1.Checked = true;
                    break;

                case "VD_Area2":
                    VD_Area2.Checked = true;
                    break;

                case "VD_Area3":
                    if (VD_Category.SelectedValue == "2")
                    {
                        SetForeColor(Color.Black, VD_Telephone_L, VD_Fax_Number_L); 
                    }
                    else 
                    {
                        SetForeColor(Color.Blue, VD_Telephone_L, VD_Fax_Number_L);
                    }
                    VD_Area3.Checked = true;
                    break;
            }
        }
        #endregion

        #region Payt_Terms
        protected void VD_Payt_Terms_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch ((sender as Anthem.DropDownList).ID)
            { 
                case "VD_Payt_Terms":
                    if(VD_Category .SelectedValue == "1")
                        VD_Payment_Terms.SelectedValue = VD_Payt_Terms.SelectedValue;
                    break;

                case "VD_Payment_Terms":
                    VD_Payt_Terms.SelectedValue = VD_Payment_Terms.SelectedValue;
                    break;
            }
        }
        #endregion

        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VD, P_SA,P_SA2);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_L":
                    VD_L.CssClass = "tabs2";
                    P_VD.Visible = true;
                    break;
                case "SA_L":
                    SA_L.CssClass = "tabs2";
                    P_SA.Visible = true;
                    break;
                case "SA2_L":
                    SA2_L.CssClass = "tabs2";
                    P_SA2.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_L.Visible = VD.Checked;
            SA_L.Visible = SA.Checked;
            SA2_L.Visible = SA2.Checked;

            SetVisible(false, P_VD, P_SA,P_SA2);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";

            //默认第1个显示 Tabs被选中
            if (VD_L.Visible)
            {
                VD_L.CssClass = "tabs2";
                P_VD.Visible = true;
                return;
            }

            if (SA_L.Visible)
            {
                SA_L.CssClass = "tabs2";
                P_SA.Visible = true;
                return;
            }

            if (SA2_L.Visible)
            {
                SA2_L.CssClass = "tabs2";
                P_SA2.Visible = true;
                return;
            }
        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                //VD_Recon_Account.Items.Clear();
                //VD_Recon_Account.Items.Add(new ListItem("", ""));
                //IList<m_Vender_Recon_Account> vras = (m_Vender_Recon_Account.status == 1).List<m_Vender_Recon_Account>();
                //foreach (m_Vender_Recon_Account vra in vras)
                //{
                //    VD_Recon_Account.Items.Add(new ListItem(vra.Recon_Account + ", " + vra.Description, vra.Recon_Account));
                //}

                VD_Payt_Terms.Items.Clear();
                VD_Payt_Terms.Items.Add(new ListItem("", ""));
                VD_Payment_Terms.Items.Clear();
                VD_Payment_Terms.Items.Add(new ListItem("", ""));
                IList<m_HK_Payment_Terms> pts = (m_HK_Payment_Terms.status == 1).List<m_HK_Payment_Terms>();
                foreach (m_HK_Payment_Terms pt in pts)
                {
                    VD_Payt_Terms.Items.Add(new ListItem(pt.Code + ", " + pt.Baseline_Date, pt.Code));
                    VD_Payment_Terms.Items.Add(new ListItem(pt.Code + ", " + pt.Baseline_Date, pt.Code));
                }


                SA_Payt_Terms.Items.Clear();
                SA_Payt_Terms.Items.Add(new ListItem("", ""));
                IList<m_HK_Payment_Terms> pts1 = (m_HK_Payment_Terms.status == 1).List<m_HK_Payment_Terms>();
                foreach (m_HK_Payment_Terms pt in pts1)
                {
                    SA_Payt_Terms.Items.Add(new ListItem(pt.Code + ", " + pt.Baseline_Date, pt.Code));
                }

                VD_Schema_Group.Items.Clear();
                VD_Schema_Group.Items.Add(new ListItem("", ""));
                IList<m_Schema_Group> pts2 = (m_Schema_Group.status == 1).List<m_Schema_Group>();
                foreach (m_Schema_Group pt in pts2)
                {
                    VD_Schema_Group.Items.Add(new ListItem(pt.Schema_Group, pt.Schema_Group));
                }


                VD_Purchasing_Group.Items.Clear();
                VD_Purchasing_Group.Items.Add(new ListItem("", ""));
                IList<m_HKPurchasingGroup> pgs = (m_HKPurchasingGroup.status == 1).List<m_HKPurchasingGroup>();
                foreach (m_HKPurchasingGroup pg in pgs)
                {
                    VD_Purchasing_Group.Items.Add(new ListItem(pg.Purchase_Group + ", " + pg.Description, pg.Purchase_Group));
                }

                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            #region VD
            List<Regular> regs = new List<Regular>();
            if (VD.Checked && SA.Checked ) { regs.Add(new Regular(RegularExp.NotEmpty, "", "Vendor: 选择了Employee 则不能选Vendor")); }
            if (VD.Checked && VD_Category.SelectedValue == "1")
            {
                
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Description_1.Text, "Vendor: Description 1 (EN) 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, VD_Vendor_Type.SelectedValue, "Vendor: Vendor Type 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Street.Text, "Vendor: Street 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Country.Text, "Vendor: Country 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Region.SelectedValue, "Vendor: Region 必填"));
                
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Language.SelectedValue, "Vendor: Language 必填"));
                if (VD_Area3.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, VD_Telephone.Text, "Vendor: Telephone 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, VD_Fax_Number.Text, "Vendor: Fax Number 必填"));
                }
                
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Recon_Account.SelectedValue, "Vendor: Recon.Account in G/L 必填"));
                
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Payt_Terms.SelectedValue, "Vendor: Payt Terms 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Payment_Methods.SelectedValue, "Vendor: Payment Methods 必填"));
                
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Order_Currency.Text, "Vendor: Order Currency 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, VD_Payment_Terms.SelectedValue, "Vendor: Payment Terms 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Purchasing_Group.SelectedValue, "Vendor: Purchasing Group 必填"));
            }

            if (VD.Checked && VD_Category.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Vendor_Master_Code.Text, "Vendor: Vendor 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Vendor_Type.SelectedValue, "Vendor: Vendor Type 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, VD_Vendor_Type.SelectedValue, "Vendor: Vendor Type 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, VD_Description_1.Text, "Vendor: Description 1 (EN) 必填"));
            }
            #endregion

            #region SA
            if (SA.Checked && VD_Category.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Name.Text, "Employee: Name 必填"));
                //if (SA2.Checked)
                //{
                //    regs.Add(new Regular(RegularExp.NotEmpty, SA_Email.Text, "Employee: Email 必填"));
                //    regs.Add(new Regular(RegularExp.NotEmpty, SA_Cell_Phone.Text, "Employee: Cell Phone 必填"));
                //}

                regs.Add(new Regular(RegularExp.NotEmpty, SA_Employee_Code.Text, "Employee: Employee Code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Sales_Person.SelectedValue, "Employee: Sales Person 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Payt_Terms.SelectedValue, "Employee: Payt Terms 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Payment_Methods.SelectedValue, "Employee: Payment Methods 必填"));

               
            }

            if (SA.Checked && VD_Category.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Vendor_Master_Code.Text, "Employee: Vendor Master Code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Name.Text, "Employee: Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Employee_Code.Text, "Employee: Employee Code 必填"));
            }
            #endregion

            #region SA2
            if (SA2.Checked && VD_Category.SelectedValue == "1")
            {

                regs.Add(new Regular(RegularExp.NotEmpty, SA2_From_Date.Text, "Sales Person: From Date 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_EE_Group.SelectedValue, "Sales Person: EE Group 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_EE_Sub_Group.Text, "Sales Person: EE Sub Group 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_Subarea.SelectedValue, "Sales Person: Subarea 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_Action_Type.SelectedValue, "Sales Person: Action Type 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_Title.SelectedValue, "Sales Person: Title 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_Last_Name.Text, "Sales Person: Last Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_First_Name.Text, "Sales Person: First Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_Gender.SelectedValue, "Sales Person: Gender 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_Birth_Date.Text, "Sales Person: Birth date 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_Nationality.Text, "Sales Person: Nationality 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_City.Text, "Sales Person: City 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_Mobile_Phone_Number.Text, "Sales Person: Mobile Phone Number 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, SA2_EMail_Address.Text, "Sales Person: EMail Address 必填"));
            }

            if (SA2.Checked && VD_Category.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SA2_Personnel_NO.Text, "Sales Person: Personnel NO 必填"));
            }
            #endregion

            if ((VD.Checked || SA.Checked) && VD_Category.SelectedValue == "1" && TaskAPI.Step == "DMO Maintain" && Assessment1.Assessment.Opinion == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SAP_Code.Text, "Sap Code 必填！"));
            }

            if (TaskAPI.Step == "DMO Maintain" & Assessment1.Assessment.Opinion == "1")
            {
                //if ((Creation_Number.Text == "" | Creation_Time.Text == "") & (Revision_Number.Text == "" | Revision_Time.Text == ""))
                //{
                //    regs.Add(new Regular(RegularExp.NotEmpty, "", "Creation和Revision必有一项必填"));
                //}
                if (SA2.Checked & VD_Category.SelectedValue == "1")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, DMO_SalesSAP_Code.Text, "Sales SAP Code 必填"));
                }
            }

            return Validation(regs);
        }

        //新增workload数据验证方法
        //private List<string> DataValidations()
        //{
        //    List<Regular> regs = new List<Regular>();
        //    if (VD_Category.SelectedValue == "1" || VD_Category.SelectedValue == "2" || VD_Category.SelectedValue == "3" || VD_Category.SelectedValue == "4")
        //    {
        //        if (TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check")
        //        {
        //            regs.Add(new Regular(RegularExp.NotEmpty, WorkLoad.Text.Trim(), WorkLoad_L.Text + "不能为空"));
        //        }
        //    }
        //    return Validation(regs);
        //}

        #endregion

        #region 方法 Others
        protected void VD_Payment_Methods_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }
        private string getFormCheckList(Anthem .CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem .CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion

        #region 事件 Recon Account
        protected void VD_Recon_Account_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (VD_Recon_Account.SelectedValue)
            { 
                case"16110000":
                    VD_Cash_Mgmnt_Group.Text = "A1－External domestic vendor";
                    break;

                case "16210000":
                    VD_Cash_Mgmnt_Group.Text = "A2－External foreign vendor";
                    break;

                case "16410000":
                    VD_Cash_Mgmnt_Group.Text = "A3－AkzoNobel inter co";
                    break;

                default:
                    VD_Cash_Mgmnt_Group.Text = "";
                    break;
                
                
            
            }
            
            
            //if (VD_Recon_Account.SelectedValue == "16110000")
            //{
            //    VD_Cash_Mgmnt_Group.Text = "A1－External domestic vendor";
            //}

            //if (VD_Recon_Account.SelectedValue == "16210000")
            //{
            //    VD_Cash_Mgmnt_Group.Text = "A2－External foreign vendor";
            //}

            //if (VD_Recon_Account.SelectedValue == "16410000")
            //{
            //    VD_Cash_Mgmnt_Group.Text = "A3－AkzoNobel inter co";
            //}

            //if (VD_Recon_Account.SelectedValue == "")
            //{
            //    VD_Cash_Mgmnt_Group.Text = "";
            //}

          
        }
        #endregion

        #region 事件 Search Term
        protected void VD_Search_Term_TextChanged(object sender, EventArgs e)
        {
            VD_Search_Term.Text = VD_Description_1.Text;

            if (VD_Description_2.Text == "")
            {
                DMO_Employee_Name.Text = VD_Description_1.Text;
            }
            else if (VD_Description_1.Text == "")
            {
                DMO_Employee_Name.Text = VD_Description_2.Text;
            }
            else if (VD_Description_1.Text != "" & VD_Description_2.Text != "")
            {
                DMO_Employee_Name.Text = VD_Description_2.Text;
            }
        }
        #endregion

        protected void SA_Name_TextChanged(object sender, EventArgs e)
        {
            DMO_Employee_Name.Text = SA_Name.Text;
        }

       
    }
}